package com.cooksys.film_rental.bo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooksys.film_rental.bo.InventoryBo;
import com.cooksys.film_rental.dao.InventoryDao;
import com.cooksys.film_rental.model.Film;
import com.cooksys.film_rental.model.Inventory;
import com.cooksys.film_rental.model.Rental;
import com.cooksys.film_rental.model.Store;

@Service("InventoryBo")
public class InventoryBoImpl implements InventoryBo {

	@Autowired(required = true)
	InventoryDao inventoryDao;

	@Override
	public Inventory getInventoryByInventoryId(Integer inventoryId) {
		return this.inventoryDao.getInventoryByInventoryId(inventoryId);
	}

	@Override
	public Inventory getInventoryByInventoryId(String inventoryId) {
		try {

			Integer inventoryIdAsInteger = Integer.valueOf(inventoryId);
			return this.getInventoryByInventoryId(inventoryIdAsInteger);

		} catch (NumberFormatException e) {

			System.err
					.println("Could not parse Integer value for inventoryId from string: "
							+ inventoryId);
			e.printStackTrace();
			System.err.println("Returning null value...");
			return null;

		}
	}

	@Override
	public List<Inventory> searchInventoriesByStore(Store store) {
		return this.inventoryDao.searchInventoriesByStore(store);
	}

	@Override
	public List<Inventory> searchInventoriesByFilm(Film film) {
		return this.inventoryDao.searchInventoriesByFilm(film);
	}

	@Override
	public Inventory getInventoryByRental(Rental rental) {
		return this.inventoryDao.getInventoryByRental(rental);
	}

	@Override
	public Inventory getInventoryByFilmAndStore(Film film, Store store) {
		return this.inventoryDao.getInventoryByFilmAndStore(film, store);
	}

}
